<#include "../common/layout/__mainlayout.html">
<#include "../common/__pagination.html">

<!-- page specific plugin styles -->
        <!--设置面包屑-->
        <#assign pageBreadCrumbs>
            <li class="active"><a href="#">应用管理</a></li>
            <li class="active">编辑软件信息</li>
        </#assign>


        <#assign pageCss>
            <!-- page specific plugin styles -->
            <link rel="stylesheet" href="${ctx}/static/admin/assets/css/jquery-ui.custom.css"/>
            <link rel="stylesheet" href="${ctx}/static/admin/assets/css/chosen.css"/>
            <link rel="stylesheet" href="${ctx}/static/admin/assets/css/datepicker.css"/>
        </#assign>

        <#assign pageJavascript>
        <script src="${ctx}/static/admin/assets/js/jquery.dataTables.js"></script>
        <script src="${ctx}/static/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
        <script src="${ctx}/static/admin/assets/js/ajaxfileupload.js"></script>
        <script src="${ctx}/static/admin/assets/js/bootstrap-wysiwyg.js"></script>

        <script type="text/javascript">
            var $path_assets = "${ctx}/static/admin/assets/";//this will be used in loading jQuery UI if needed!
        </script>
        <script type="text/javascript">
            jQuery(function($){
                //初始化数据展示
                $("#isAccredit").val(${vo.isAccredit!});
                $("#sysStarsEnable").val(${vo.sysStarsEnable!});
                $("#sysStars").val(${vo.sysStars!});
                $("#commentStars").val(${vo.commentStars!});
                $("#isOfficial").val(${vo.isOfficial!});
                $("#categoryId").val(${vo.categoryId!});
                $("#categoryId2").val(${vo.categoryId2!});
                $("#categoryId3").val(${vo.categoryId3!});


                if(!ace.vars['touch']) {
                    $('.chosen-select').chosen({allow_single_deselect:true});
                    //resize the chosen on window resize

                    $(window)
                            .off('resize.chosen')
                            .on('resize.chosen', function() {
                                $('.chosen-select').each(function() {
                                    var $this = $(this);
                                    $this.next().css({'width': $this.parent().width()});
                                })
                            }).trigger('resize.chosen');
                    //resize chosen on sidebar collapse/expand
                    $(document).on('settings.ace.chosen', function(e, event_name, event_val) {
                        if(event_name != 'sidebar_collapsed') return;
                        $('.chosen-select').each(function() {
                            var $this = $(this);
                            $this.next().css({'width': $this.parent().width()});
                        })
                    });


                    $('#chosen-multiple-style .btn').on('click', function(e){
                        var target = $(this).find('input[type=radio]');
                        var which = parseInt(target.val());
                        if(which == 2) $('#form-field-select-4').addClass('tag-input-style');
                        else $('#form-field-select-4').removeClass('tag-input-style');
                    });
                }

                $("#categoryId").change(function () {
                    //清除二级下拉列表
                    $("#categoryId2").empty();
                    $("#categoryId3").empty();
                    if($(this).val() !=0){

                        $("#categoryId2").append($("<option/>").text("--请选择二级分类--").attr("value","0"));
                        //要请求的二级下拉JSON获取页面
                        var url="${ctx}/admin/category/categoryList.do";
                        //将选中的一级下拉列表项的id传过去
                        $.getJSON(url, { parentId:$(this).val() },function (data) {
                            //对请求返回的JSON格式进行分解加载
                            $(data.data).each(function () {
                                $("#categoryId2").append($("<option/>").text(this.categoryName).attr("value",this.id));
                            });
                        });
                    }
                });

                $("#categoryId2").change(function () {
                    //清除二级下拉列表
                    $("#categoryId3").empty();
                    if($(this).val() !=0){
                        $("#categoryId3").append($("<option/>").text("--请选择三级分类--").attr("value","0"));
                        //要请求的二级下拉JSON获取页面
                        var url="${ctx}/admin/category/categoryList.do";
                        //将选中的一级下拉列表项的id传过去
                        $.getJSON(url, { parentId:$(this).val() },function (data) {
                            //对请求返回的JSON格式进行分解加载
                            $(data.data).each(function () {
                                $("#categoryId3").append($("<option/>").text(this.categoryName).attr("value",this.id));
                            });
                        });
                    }

                });

                $("#bootbox-checkno").on(ace.click_event, function() {
                    bootbox.prompt("请填写不通过原因", function(result) {
                        if (result === null) {

                        } else {
                            if(result==""){
                                alert("请填写不通过原因");
                                return false;
                            }
                            $("#checkReason").val(result);
                            submitSoft(4);
                        }
                    });
                });


                function showErrorAlert (reason, detail) {
                    var msg='';
                    if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
                    else {
                        //console.log("error uploading file", reason, detail);
                    }
                    $('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+
                    '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
                }

                $('#descriptiondiv').ace_wysiwyg({
                    toolbar:
                            [
                                'font',
                                null,
                                'fontSize',
                                null,
                                {name:'bold', className:'btn-info'},
                                {name:'italic', className:'btn-info'},
                                {name:'strikethrough', className:'btn-info'},
                                {name:'underline', className:'btn-info'},
                                null,
                                {name:'insertunorderedlist', className:'btn-success'},
                                {name:'insertorderedlist', className:'btn-success'},
                                {name:'outdent', className:'btn-purple'},
                                {name:'indent', className:'btn-purple'},
                                null,
                                {name:'justifyleft', className:'btn-primary'},
                                {name:'justifycenter', className:'btn-primary'},
                                {name:'justifyright', className:'btn-primary'},
                                {name:'justifyfull', className:'btn-inverse'},
                                null,
                                {name:'createLink', className:'btn-pink'},
                                {name:'unlink', className:'btn-pink'},
                                null,
                                {name:'insertImage', className:'btn-success'},
                                null,
                                'foreColor',
                                null,
                                {name:'undo', className:'btn-grey'},
                                {name:'redo', className:'btn-grey'}
                            ],
                    'wysiwyg': {
                        fileUploadError: showErrorAlert
                    }
                }).prev().addClass('wysiwyg-style2');

                $("#softItemForm").validate({
                    errorElement: 'div',
                    errorClass: 'help-block',
                    focusInvalid: true,
                    highlight: function (e) {
                        $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
                    },
                    success: function (e) {
                        $(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
                        $(e).remove();
                    },
                    errorPlacement: function (error, element) {
                        if (element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
                            var controls = element.closest('div[class*="col-"]');
                            if (controls.find(':checkbox,:radio').length > 1) controls.append(error);
                            else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
                        }
                        else if (element.is('.select2')) {
                            error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
                        }
                        else if (element.is('.chosen-select')) {
                            error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
                        }
                        else error.insertAfter(element.parent());
                    },

                    submitHandler: function (form) {
                        $.ajax({
                            cache: true,
                            type: "POST",
                            url:"${ctx}/admin/soft/save.do",
                            data:$('#softItemForm').serialize(),// 你的formid
                            async: false,
                            error: function(request) {
                                alert("Connection error");
                            },
                            success: function(data) {
                                if(data.result == "success"){
                                    window.location="${refer!}";
                                }else{
                                    alert(data.messages);
                                }
                            }
                        });
                    },
                    invalidHandler: function (form) {
                    }
                });
            })
        </script>

        <script type="text/javascript">

            function submitSoft(submitType){
                var categoryId = $("#categoryId").val();
                if(categoryId == 0){
                    alert("请选择分类");
                    return false;
                }
                $('#softItemForm').submit();
            }

            $('#id-input-apk,#id-input-icon,#id-input-gamecut,#id-input-ad,#id-input-screenshot').ace_file_input({
                no_file:'未选择文件 ...',
                btn_choose:'浏览',
                btn_change:'更改',
                droppable:false,
                onchange:null,
                thumbnail:false //| true | large
                //whitelist:'gif|png|jpg|jpeg'
                //blacklist:'exe|php'
                //onchange:''
                //
            });


        </script>
        </#assign>
    <@mainlayout pageBreadCrumbs=pageBreadCrumbs pageCss=pageCss pageJavascript=pageJavascript currentMenu="ApplicationFlag">
    <form id="softItemForm" class="form-horizontal" action="${ctx}/admin/soft/save.do" method="post">

            <!---软件信息----->
            <div class="row">
                <div class="col-sm-12">
                    <div class="widget-box">
                        <div class="widget-header">
                            <h4 class="widget-title">软件信息</h4>

                        </div>

                        <div class="widget-body">
                            <div class="widget-main">
                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2" for="softId">软件编号:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" readonly="" name="softId" id="softId" class="form-control col-sm-4 required" value="${vo.softId!}"/>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="lastSoftItemId">最新版本:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" readonly="" name="lastSoftItemId" id="lastSoftItemId" class="form-control col-sm-4" value="${vo.lastSoftItemId!}"/>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2" for="packageName">软件包名:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" readonly="" name="packageName" id="packageName" class="form-control col-sm-4 required" value="${vo.packageName!}"/>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="softName">软件名称:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" name="softName" id="softName" <#if readonly?? >readonly=""</#if> class="form-control col-sm-4 required" value="${vo.softName!}"/>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2" for="isAccredit">是否授权:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <div>
                                                <select class="form-control" name="isAccredit" id="isAccredit" data-placeholder="Choose a State..."  <#if readonly?? >readonly=""</#if> >
                                                    <option value="1" >是</option>
                                                    <option value="0" >否</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="sysStarsEnable">开启星级:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <div>
                                                <select class=" form-control" name="sysStarsEnable" id="sysStarsEnable"  data-placeholder="Choose a State..." <#if readonly?? >readonly=""</#if> >
                                                    <option value="0">关闭</option>
                                                    <option value="1">开启</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2" for="sysStars">系统星级:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <div>
                                                <select class="form-control" name="sysStars" id="sysStars"  <#if readonly?? >readonly=""</#if>  data-placeholder="Choose a star...">
                                                    <option value=""></option>
                                                    <#list starEnums?keys as key>
                                                        <option value="${starEnums[key]?default('')}">${key}</option>
                                                    </#list>
                                                </select>
                                            </div>
                                        </div>
                                    </div>

                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="commentStars">评论星级:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <div>
                                                <select class="form-control" name="commentStars" id="commentStars" readonly=""   data-placeholder="Choose a star...">
                                                    <option value=""></option>
                                                    <#list starEnums?keys as key>
                                                        <option value="${starEnums[key]?default('')}">${key}</option>
                                                    </#list>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2" for="isOfficial">是否官方:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <div>
                                                <select class="form-control" name="isOfficial" id="isOfficial" <#if readonly?? >readonly=""</#if>  data-placeholder="Choose a State...">
                                                    <option value="1">是</option>
                                                    <option value="0">否</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="downloadNumber">总下载量:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="number" name="downloadNumber" id="downloadNumber" <#if readonly?? >readonly=""</#if>  class="form-control col-sm-4" value="${vo.downloadNumber!}"/>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2" for="seo">搜索关键词（用空格隔开）:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" name="seo" id="seo"  <#if readonly?? >readonly=""</#if> class="form-control col-sm-4 required" value="${vo.seo!}"/>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="developerName">开发者名称:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" name="developerName" id="developerName" <#if readonly?? >readonly=""</#if>  class="form-control col-sm-4 " value="${vo.developerName!}"/>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2" for="developerPhone">开发者手机/电话:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" name="developerPhone" id="developerPhone" <#if readonly?? >readonly=""</#if>  class="form-control col-sm-4 " value="${vo.developerPhone!}"/>
                                        </div>
                                    </div>
                                    <label class="control-label col-xs-12 col-sm-2 no-padding-right" for="developerEmail">开发者邮箱:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" name="developerEmail" id="developerEmail" <#if readonly?? >readonly=""</#if>  class="form-control col-sm-4 " value="${vo.developerEmail!}"/>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2" for="developerSite">开发者网站:</label>
                                    <div class="col-xs-12 col-sm-4">
                                        <div class="clearfix">
                                            <input type="text" name="developerSite" id="developerSite" <#if readonly?? >readonly=""</#if>  class="form-control col-sm-4 " value="${vo.developerSite!}"/>
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2" for="categoryId">软件分类:</label>
                                    <div class="col-xs-12 col-sm-3">
                                        <div class="clearfix">
                                            <div>
                                                <select class="form-control required" name="categoryId" id="categoryId" <#if readonly?? >readonly=""</#if>  data-placeholder="请选择一级分类">
                                                <option value="0">--请选择一级分类--</option>
                                                <#list firstCatagories as first>
                                                    <option value="${first.id}" >
                                                        ${(first.categoryName)!}
                                                    </option>
                                                </#list>
                                                </select>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-xs-12 col-sm-3">
                                        <div class="clearfix">
                                            <div>
                                                <select class=" form-control" name="categoryId2" id="categoryId2" <#if readonly?? >readonly=""</#if>  data-placeholder="请选择二级分类">
                                                <option value="0">请选择二级分类</option>
                                                <#if secondCatagories??>
                                                    <#list secondCatagories as sec>
                                                        <option value="${sec.id}" >
                                                            ${(sec.categoryName)!}
                                                        </option>
                                                    </#list>
                                                </#if>
                                                </select>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-xs-12 col-sm-3">
                                        <div class="clearfix">
                                            <div>
                                                <select class=" form-control" name="categoryId3" id="categoryId3" <#if readonly?? >readonly=""</#if>  data-placeholder="请选择三级分类">
                                                <option value="0">请选择三级分类</option>
                                                <#if thirdCatagories??>
                                                    <#list thirdCatagories as third>
                                                        <option value="${third.id}" >
                                                            ${(third.categoryName)!}
                                                        </option>
                                                    </#list>
                                                </#if>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                                <div class="form-group">
                                    <div>
                                        <label class="control-label col-xs-12 col-sm-2" for="summary">软件简介:</label>
                                        <div class="control-label col-xs-10 col-sm-10 " >
                                            <textarea class=" col-sm-10 limited required" id="summary" name="summary" <#if readonly?? >readonly=""</#if>  maxlength="500">${vo.summary!}</textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label col-xs-12 col-sm-2" for="descriptiondiv">软件详细内容:</label>
                                    <div class="col-sm-10 " >
                                        <#if !readonly?? >
                                            <div class="wysiwyg-editor " id="descriptiondiv" name="descriptiondiv"  style="border:1px solid #d5d5d5">${vo.description!}</div>
                                        <#else>
                                            <div  name="descriptiondiv"  style="border:1px solid #d5d5d5" >${vo.description!}</div>
                                        </#if>
                                        <textarea hidden="hidden" id="description" name="description">${vo.description!}</textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

                <div class="clearfix form-actions">
                    <div class="col-md-offset-3 col-md-9">
                        <button class="btn btn-info" type="button"  onclick="submitSoft(0)">
                            <i class="ace-icon fa fa-check bigger-110"></i> 保存
                        </button>
                        &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;
                        <button class="btn" type="button" onclick="window.location='${refer!}';">
                            <i class="ace-icon fa fa-undo bigger-110"></i> 取消
                        </button>
                    </div>
                </div>
        </form>
</@mainlayout>
<script src="${ctx}/static/admin/assets/js/jquery.validate.js"></script>
<script src="${ctx}/static/admin/assets/js/jquery.validate.messages_zh.js"></script>
